int left(int p,int q){return p+1==q || p==4 && q==0;}
int right(int p,int q){return left(q,p);}
int near(int p,int q){return left(p,q)||right(p,q);}

void shuffle0(int *a,int n){
    int i,j,t;
    for(i=0;i<n;i++){
        j=rand()%(n-i)+i;//[i,n-1]
        t=a[i],a[i]=a[j],a[j]=t;
        }
}
int random(const void*a,const void*b){
    return rand()%3-1;
}
void shuffle1(int *a,int n){
    qsort(a,n,sizeof(a[0]),random);
}

int main(){
   // srand(time(NULL));
    int a[]={1,2,3,4};
    int zhao=0,qian,sun,li,zhou;
    while(1){
        shuffle1(a,4);
        qian=a[0],sun=a[1],li=a[2],zhou=a[3];
        int zp=near(zhao,qian),zq=left(sun,qian)||left(li,qian);
        int lp=left(qian,sun),lq=near(li,sun);
        if(zp+zq+lp+lq==0){
                printf("zhao=%d qian=%d sun=%d li=%d zhou=%d\n",zhao,qian,sun,li,zhou);
                break;
            }
    }

}
